import { Injectable } from '@angular/core';
import { Router, Route, NavigationStart } from '@angular/router';
import { filter, pluck } from 'rxjs/operators';

@Injectable({
  providedIn: 'root'
})
export class MainNavService {
  private _mainNavConfig = [
    {
      icon: 'icon-location',
      path: '/home'
    },
    {
      icon: 'icon-star',
      path: '/next'
    },
    {
      icon: 'icon-phone',
      path: '/end'
    }
  ];

  private _showMainNavPath = new Set(
    [
      '/',
      '/home',
      '/next',
      '/end'
    ]
  );

  public showMainNav = false;

  constructor(private router: Router) {
    this.hiddenNavBar();
  }
  public getMainNavConfig() {
    return this._mainNavConfig;
  }
  public hiddenNavBar() {
    const _this = this;
     this.router.events.pipe(
      filter(item => {
        return item instanceof NavigationStart;
      }),
      pluck('url')
     ).subscribe((url: string) => {
        _this.showMainNav = _this._showMainNavPath.has(url);
     });
  }
}
